#include "serverwindow.h"
#include "ui_serverwindow.h"
#include<QDebug>
#include<QTime>
#include<QDate>
#include<QMessageBox>
#include<QFile>
#include<QJsonArray>
#include<QJsonDocument>
#include<QJsonObject>
#include<QJsonValue>
#include<cstdlib>
#include<unistd.h>
#include<QStack>
#include<QDir>
#include<QSqlDatabase>
#include<QSqlQuery>
#include<QDate>
#include<QTime>
#define logPath "./data/serverLog.txt"



serverWindow::serverWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::serverWindow)
{
    ui->setupUi(this);
    t1=new mythread(this);
    connect(t1,&mythread::updateTime,this,&serverWindow::showDateTime);
    t1->start();
    logFile=new QFile(logPath);
    if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
    {
        qDebug()<<"log file open failed";


    }

    QSqlDatabase staffData=QSqlDatabase::addDatabase("QSQLITE");
    staffData.setDatabaseName("./data/staff.db");

    if(!staffData.open())
    {
        qDebug()<<"open database failed";
        logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                       "ERROR:员工数据库打开失败|"+"\r\n");

        logFile->close();
    }

    QSqlQuery query;

   if(!query.exec(QString("create table if not exists staff(名字 text primary key,密码 text,职务 text);")) )
     {
           qDebug()<<"create table fialed";
     }

   if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
   {
       qDebug()<<"log file open failed";

   }
    logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                   "服务器上线,正在等待连接客户端|"+"\r\n");

    logFile->close();

    server=new QTcpServer;
    socket=new QTcpSocket;
    connect(server,&QTcpServer::newConnection,this,&serverWindow::connected);

    server->listen(QHostAddress::Any,6065);

}

serverWindow::~serverWindow()
{
    socket->disconnectFromHost();
    server->close();
    socket->close();
    t1->terminate();
    delete server;
    delete socket;
    delete logFile;
    delete t1;
    delete ui;
}


void serverWindow::showDateTime()
{
    ui->dateAndTimelabel->setText(QDate::currentDate().toString("yy-MM-dd")+" "+QTime::currentTime().toString("hh:mm:ss"));
}




void serverWindow::connected()
{
    socket=server->nextPendingConnection();
    connect(socket,&QIODevice::readyRead,this,&serverWindow::getMessage);
    if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
    {
        qDebug()<<"log file open failed";
    }
    logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                   "客户端连接成功 IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");
    logFile->close();
}

void serverWindow::getMessage()
{


    if(socket!=nullptr)
    {



       QByteArray msgArr= socket->readAll();


      qDebug()<<msgArr;

       if(msgArr.split('#')[0]=="login"&&msgArr.split('#')[1]=="管理员")
       {

           ui->textBrowser->append("from IP:"+socket->peerAddress().toString().split(":")[3]+"  PORT:"
                                   +QString::number(socket->peerPort(),10)+"  "+
                                   QTime::currentTime().toString("hh:mm:ss")+"\r\n " + "请求登录 "+"用户名: "+msgArr.split('#')[2]+
                                   "密码: "+msgArr.split('#')[3]);

           if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
           {
               qDebug()<<"log file open failed";
           }

           logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                          "客户端请求登录| IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");

            logFile->close();

            QSqlQuery query;

           if(!query.exec(QString("select *from staff where 名字='%1';").arg(QString(msgArr.split('#')[2]))) )
             {
                   qDebug()<<"select from staff fialed";

                   if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
                   {
                       qDebug()<<"log file open failed";

                   }
                    logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                                   "数据库操作:<select from staff> 失败 |"+"\r\n");

                    logFile->close();

             }
           if(query.next()==false)
           {
               qDebug()<<"查无此人";
               if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
               {
                   qDebug()<<"log file open failed";
               }
               logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                              "客户端登录失败（用户不存在）| IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");
               logFile->close();

                       QByteArray data2= QByteArray("登录失败:用户不存在");
                        socket->write(data2);
                        ui->textBrowser_2->append(QTime::currentTime().toString("hh:mm:ss")+"\r\n "+"登录失败:用户不存在");
           }
           else
           {
               if(query.value("密码").toString()==QString(msgArr.split('#')[3])&&query.value("职务").toString()!=QString(msgArr.split('#')[1]))
                {
                   if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
                   {
                       qDebug()<<"log file open failed";
                   }
                   logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                                  "客户端登录失败（身份选择有误）| IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");
                   logFile->close();
                   QByteArray data= QByteArray("登录失败:身份选择有误");
                    socket->write(data);
                    ui->textBrowser_2->append(QTime::currentTime().toString("hh:mm:ss")+"\r\n "+"登录失败:身份选择有误");
                }
               else if(query.value("密码").toString()==QString(msgArr.split('#')[3]))
                {
                   if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
                   {
                       qDebug()<<"log file open failed";
                   }
                   logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                                  "客户端登录成功|管理员|"+ msgArr.split('#')[2]+"|IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");
                   logFile->close();
                   QByteArray data1= QByteArray("登录成功:管理员");
                    socket->write(data1);
                    ui->textBrowser_2->append(QTime::currentTime().toString("hh:mm:ss")+"\r\n "+"登录成功:管理员");
                }
               else
                {
                   if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
                   {
                       qDebug()<<"log file open failed";
                   }
                   logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                                  "客户端登录失败（密码错误）| IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");
                    logFile->close();
                           QByteArray data= QByteArray("登录失败:密码错误");
                           socket->write(data);
                           ui->textBrowser_2->append(QTime::currentTime().toString("hh:mm:ss")+"\r\n "+"登录失败:密码错误");
                }


           }




       }
       else if(msgArr.split('#')[0]=="login"&&msgArr.split('#')[1]=="员工")
       {
           ui->textBrowser->append("from IP:"+socket->peerAddress().toString().split(":")[3]+"  PORT:"
                                   +QString::number(socket->peerPort(),10)+"  "+
                                   QTime::currentTime().toString("hh:mm:ss")+"\r\n " + "请求登录 "+"用户名: "+msgArr.split('#')[2]+
                                   "密码: "+msgArr.split('#')[3]);
           if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
           {
               qDebug()<<"log file open failed";
           }
           logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                          "客户端请求登录 |IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");
          logFile->close();

          QSqlQuery query;

         if(!query.exec(QString("select *from staff where 名字='%1';").arg(QString(msgArr.split('#')[2]))) )
           {
                 qDebug()<<"select table fialed";

                 if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
                 {
                     qDebug()<<"log file open failed";

                 }
                  logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                                 "数据库操作:<select *from staff where 名字='%1'> 失败 |"+"\r\n");

                  logFile->close();


           }
         if(query.next()==false)
         {
             qDebug()<<"查无此人";
             if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
             {
                 qDebug()<<"log file open failed";
             }
             logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                            "客户端登录失败（用户不存在）| IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");
             logFile->close();

                     QByteArray data2= QByteArray("登录失败:用户不存在");
                      socket->write(data2);
                      ui->textBrowser_2->append(QTime::currentTime().toString("hh:mm:ss")+"\r\n "+"登录失败:用户不存在");
         }
         else
         {
             if(query.value("密码").toString()==QString(msgArr.split('#')[3])&&query.value("职务").toString()!=QString(msgArr.split('#')[1]))
              {
                 if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
                 {
                     qDebug()<<"log file open failed";
                 }
                 logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                                "客户端登录失败（身份选择有误）| IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");
                 logFile->close();
                 QByteArray data= QByteArray("登录失败:身份选择有误");
                  socket->write(data);
                  ui->textBrowser_2->append(QTime::currentTime().toString("hh:mm:ss")+"\r\n "+"登录失败:身份选择有误");
              }
             else if(query.value("密码").toString()==QString(msgArr.split('#')[3]))
             {
                 if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
                 {
                     qDebug()<<"log file open failed";
                 }
                 logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                                "客户端登录成功|员工|"+ msgArr.split('#')[2]+"|IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");
                 logFile->close();
                 QByteArray data1= QByteArray("登录成功:员工");
                  socket->write(data1);
                  ui->textBrowser_2->append(QTime::currentTime().toString("hh:mm:ss")+"\r\n "+"登录成功:员工");
             }
             else
              {
                 if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
                 {
                     qDebug()<<"log file open failed";
                 }
                 logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                                "客户端登录失败（密码错误）| IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");
                  logFile->close();
                         QByteArray data= QByteArray("登录失败:密码错误");
                         socket->write(data);
                         ui->textBrowser_2->append(QTime::currentTime().toString("hh:mm:ss")+"\r\n "+"登录失败:密码错误");
              }


         }


        }
       else if(msgArr.split('#')[0]=="getStaff")
       {
           ui->textBrowser->append("from IP:"+socket->peerAddress().toString().split(":")[3]+"  PORT:"
                                   +QString::number(socket->peerPort(),10)+"  "+
                                   QTime::currentTime().toString("hh:mm:ss")+"\r\n " + "请求获取员工信息");
           if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
           {
               qDebug()<<"log file open failed";
           }

           logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                          "客户端请求获取员工信息 |IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");

           logFile->close();
           QSqlQuery query;

          if(!query.exec(QString("select *from staff;")) )
            {
                  qDebug()<<"select from staff fialed";
                  if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
                  {
                      qDebug()<<"log file open failed";

                  }
                   logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                                  "数据库操作:<select from staff> 失败 |"+"\r\n");

                   logFile->close();

            }

          while(query.next())
         {
              QString sdata=QString("+"+query.value("名字").toString()+":"+
                                    query.value("职务").toString()+":"+
                                    query.value("密码").toString());

              QByteArray data= QByteArray(sdata.toUtf8());

              socket->write(data);
              ui->textBrowser_2->append("已发送员工信息");


              if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
              {
                  qDebug()<<"log file open failed";

              }
              logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                             "已向客户端发送员工信息 |IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");


               logFile->close();
         }





       }

       else if(msgArr.split('#')[0]=="del")
       {
           ui->textBrowser->append("from IP:"+socket->peerAddress().toString().split(":")[3]+"  PORT:"
                                   +QString::number(socket->peerPort(),10)+"  "+
                                   QTime::currentTime().toString("hh:mm:ss")+"\r\n " + "请求删除员工信息:"+msgArr.split('#')[1]);
           if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
           {
               qDebug()<<"log file open failed";
           }

           logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                          "客户端请求删除员工信息 |IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");

           logFile->close();


           QSqlQuery query;

          if(!query.exec(QString("delete from staff where 名字='%1';").arg(QString(msgArr.split('#')[1]))) )
           {
                  qDebug()<<"delete fialed";
                  if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
                  {
                      qDebug()<<"log file open failed";
                  }

                  logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                                 "数据库操作:<delete from staff where 名字='%1'> 失败 |"+"\r\n");

                  logFile->close();
           }

          QByteArray data= QByteArray("删除成功:"+msgArr.split('#')[1]);

          if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
          {
              qDebug()<<"log file open failed";
          }

          logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                         "删除成功 |IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");

          logFile->close();


          socket->write(data);
          if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
          {
              qDebug()<<"log file open failed";
          }

          logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                         "删除成功 |被删除员工:"+msgArr.split('#')[1]+"IP"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");

          logFile->close();



       }
       else if(msgArr.split('#')[0]=="add")
       {
           ui->textBrowser->append("from IP:"+socket->peerAddress().toString().split(":")[3]+"  PORT:"
                                   +QString::number(socket->peerPort(),10)+"  "+
                                   QTime::currentTime().toString("hh:mm:ss")+"\r\n " + "请求添加员工信息:"+msgArr.split('#')[1]);

           if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
           {
               qDebug()<<"log file open failed";
           }

           logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                          "客户端请求添加员工信息 |IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");

           logFile->close();



           QSqlQuery query;
           if(!query.exec(QString("select *from staff where 名字='%1';").arg(QString(msgArr.split('#')[1]))) )
             {
                   qDebug()<<"select from staff fialed";
                   if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
                   {
                       qDebug()<<"log file open failed";
                   }

                   logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                                  "数据库操作:<select from staff> 失败 |"+"\r\n");

                   logFile->close();


             }
           if(query.next()==false)
           {
               if(!query.exec(QString("insert into staff(名字,密码,职务)values('%1','%2','%3')").arg(QString(msgArr.split('#')[1])).arg(QString(msgArr.split('#')[2])).arg(QString(msgArr.split('#')[3]))) )
                {
                       qDebug()<<"add to database fialed";
                       if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
                       {
                           qDebug()<<"log file open failed";
                       }

                       logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                                      "数据库操作:<insert into staff(名字,密码,职务)values('%1','%2','%3')> 失败 |"+"\r\n");

                       logFile->close();
                }


               QByteArray data= QByteArray("添加成功:");

               if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
               {
                   qDebug()<<"log file open failed";
               }

               logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                              "添加员工成功|IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");

               logFile->close();
                socket->write(data);


           }
           else
           {
               ui->textBrowser_2->append("from IP:"+socket->peerAddress().toString().split(":")[3]+"  PORT:"
                                       +QString::number(socket->peerPort(),10)+"  "+
                                       QTime::currentTime().toString("hh:mm:ss")+"\r\n " + "添加失败：此用户已存在");

               QByteArray data= QByteArray("添加失败:此用户已存在");

               if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
               {
                   qDebug()<<"log file open failed";
               }

               logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                              "添加失败:此用户已存在 |IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");

               logFile->close();
                socket->write(data);
           }





       }
       else if(msgArr.split('#')[0]=="getName")
        {

           ui->textBrowser_2->append("from IP:"+socket->peerAddress().toString().split(":")[3]+"  PORT:"
                                   +QString::number(socket->peerPort(),10)+"  "+
                                   QTime::currentTime().toString("hh:mm:ss")+"\r\n " + "请求获取当前操作员信息");


           QFile file(logPath);
           if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
               return;
            QStack<QString> *nameStack=new QStack<QString>;

           while (!file.atEnd()) {
               QByteArray line = file.readLine();
               QString data= QString(line);
              if(data.split('|')[2]=="客户端登录成功"&&data.split('|')[3]=="管理员")
              {
                  nameStack->push(data.split('|')[4]);
              }
           }

           socket->write(nameStack->pop().toUtf8());
        }
       else if(msgArr.split('#')[0]=="getLog")
        {
           if(!logFile->open(QIODevice::WriteOnly|QIODevice::Append))
           {
               qDebug()<<"log file open failed";
           }

           logFile->write(QDate::currentDate().toString("yy-MM-dd").toUtf8()+"|"+QTime::currentTime().toString("hh:mm:ss").toUtf8()+"|"+
                          "客户端请求获取服务器日志信息 |IP:"+socket->peerAddress().toString().split(":")[3].toUtf8()+" PROT:"+QString::number(socket->peerPort(),10).toUtf8()+"\r\n");

           logFile->close();

           QDate startday(msgArr.split('#')[1].split('-')[0].toInt(),msgArr.split('#')[1].split('-')[1].toInt()
                                                        ,msgArr.split('#')[1].split('-')[2].toInt());

           QDate endday(msgArr.split('#')[2].split('-')[0].toInt(),msgArr.split('#')[2].split('-')[1].toInt()
                                                        ,msgArr.split('#')[2].split('-')[2].toInt());

           QFile file(logPath);
           if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
               return;

           while (!file.atEnd()) {
               QByteArray line = file.readLine();
               QString data= QString(line);

               QDate tmp(data.split('|')[0].split('-')[0].toInt()+2000,data.split('|')[0].split('-')[1].toInt(),
                                                            data.split('|')[0].split('-')[2].toInt());

              if(tmp>=startday&&tmp<=endday)
              {
                 socket->write(data.toUtf8());
              }
           }


        }

}


}


